JavaScript Binary Logical Operators

Visualizing `&&`, `||`, and `??` with short-circuiting.

Logical AND (`&&`) and OR (`||`)

These operators evaluate from left to right. They are **short-circuiting**, meaning the second operand is only evaluated if necessary.

"" && "world"; // ""
"hello" && "world"; // "world"
null || "default"; // "default"
"hello" || "world"; // "hello"

Logical AND (`&&`)

Expression:

Result:

Logical OR (`||`)

Expression:

Result:


Nullish Coalescing (`??`)

The **Nullish Coalescing** operator returns the right-hand side operand only if the left-hand side operand is either **`null` or `undefined`**. It does not consider other falsy values like `0` or `''` as invalid, making it a safer alternative to `||` for providing default values.

0 ?? 10; // 0
'' ?? "default"; // ""
null ?? "default"; // "default"

Nullish Coalescing (`??`)

Expression:

Result: